####### SCRIPT FOR: 
####### DISTANCE AND TRUST: 
####### EXAMINATION OF THE TWO OPPOSING FACTORS IMPACTING ADOPTION OF POSTAL VONTING AMONG INDIVIDUALS


rm(list=ls())
gc()

setwd("C:/Users/miros/Desktop/Publications/031 - Distance and Trust - An Examination of the Two Opposing Factors Impacting Adoption of Postal Voting")


# Disabling scientific notations
options(scipen=999)



# DATA: Import ------------------------------------------------------------

library(haven)
data <- read_sav("03-data/FACE data FINAL_subset.sav")



# DATA: Recoding variables ------------------------------------------------

# Vote2019: Turnout in 2019
# Q19: Sometimes people choose not to vote. Did you vote in Finnish parliamentary elections in 2019?	
# 1: Yes
# 2: No
# 3: I wasn't entitled to vote
data$Vote2019 <- NA
data$Vote2019[data$Q19 == 1] <- "Yes"
data$Vote2019[data$Q19 == 2] <- "No"
data$Vote2019 <- factor(data$Vote2019, levels = c("Yes", "No"))


# Vote2019How: Method for voting in 2019
# Q20: How did you vote / which method did you use to cast your vote?	
# 1: Postal voting
# 2: Advance voting abroad
# 3: Advance voting in Finland
# 4: Election day voting in Finland
data$Vote2019How <- NA
data$Vote2019How[data$Q20 == 1] <- "Postal voting"
data$Vote2019How[data$Q20 == 2] <- "Advance voting abroad"
data$Vote2019How[data$Q20 == 3] <- "Advance voting in Finland"
data$Vote2019How[data$Q20 == 4] <- "Election day voting in Finland"
data$Vote2019How <- factor(data$Vote2019How, levels = c("Postal voting", "Advance voting abroad", "Advance voting in Finland", "Election day voting in Finland"))

# PostalVote
# Adding a binary variable - voting via post
data$PostalVote <- NA
data$PostalVote[data$Q20 == 1] <- 1
data$PostalVote[data$Q20 == 2] <- 0
data$PostalVote[data$Q20 == 3] <- 0
data$PostalVote[data$Q20 == 4] <- 0
data$PostalVote <- as.factor(data$PostalVote)




# DATA: Distance(s) from the polling station ----------------

# Importing data with "objective" distances
# NOTE: Calculation of these distances is based on code "PostalVote-Distances.R" shared too
#       It is separated due to privacy constraints (because it includes respondents addresses). 
#       Output of the code is imported here.
library(readr)
distances <- read_csv("03-data/Distances - anonymized.csv")
distances$X1 <- NULL

# Adding data on distances to the FACE data
data <- merge(data, distances, by.x = "Q1", by.y = "Respondent.ID", all.x = TRUE)
rm(distances)

# Transforming the objective distance measure from meters to kilometers
data$Distance <- data$Distance/1000

# Distance.Objective: Objective distance based on Google Maps
data$Distance.Objective <- data$Distance


# Distance.Subjective
# Q26: What is the distance from where you live to the nearest polling station where you 
# can vote in Finnish elections (approximately, kilometers)?		
# Write-in response [number]
data$Distance.Subjective <- data$Q26




# DATA: Association between the two distance measures ---------------------

# The analysis uses logged measures, therefore survey answer equal to 0km is transformed into 0.1km
data$Distance.Subjective[data$Distance.Subjective == 0] <- 0.1
# Also, two respondents stated (apparently as a joke) that their distance from the nearest polling station is
# 62000 and 1000000 km. These two outliers are eliminated
data$Distance.Subjective[data$Distance.Subjective > 10000] <- NA


# Calculation of Spearman's rank correlation coefficient (due to skewed data)
cor(data.frame(data$Distance.Subjective, data$Distance.Objective), use = "pairwise.complete.obs", method = "spearman")
# Spearman's p = 0.84


# Figure A1: Comparison of the two distance measures
library(ggplot2)
ggplot(subset(data, Distance.Subjective != 0.1), aes(x = Distance.Subjective, y = Distance.Objective)) +
  geom_point() +
  scale_x_log10(breaks = c(0.1, 1, 10, 100, 1000, 10000), labels = c("0.1", "1", "10", "100", "1000", "10000")) + 
  scale_y_log10(breaks = c(0.1, 1, 10, 100, 1000, 10000), labels = c("0.1", "1", "10", "100", "1000", "10000")) +
  coord_cartesian(xlim = c(0.1, 10000), ylim = c(0.1, 10000), expand = FALSE) +
  geom_abline(intercept = 0, slope = 1, colour = "gray80") +
  labs(x = "Survey question: What is the distance from where you live to the nearest polling station\nwhere you can vote in Finnish elections (approximately, kilometers)? (logged scale)",
       y = "Calculated distance: Distance between respondent's address and\nthe nearest polling station abroad in kilometers (logged scale)") +
  #geom_smooth(method = "lm") +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black"),
        axis.ticks = element_line(colour = "black"),
        panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid.major.x = element_line(colour = "gray90"),
        panel.grid.minor.x = element_line(colour = "gray90"),
        panel.grid.major.y = element_line(colour = "gray90"),
        panel.grid.minor.y = element_line(colour = "gray90"),
        panel.background = element_blank(),
        plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),"cm"))

ggsave(filename = "04-figures and models/FigA1 - Comparison of the two distance measures (log10).png", width = 17.5, height = 17.5, units = "cm", dpi = 600)




# DATA: Control variables - Re-coding --------------------------------------

# Gender
# Q56: Do you identify as...	
# 1: Male
# 2: Female
# 3: Other gender
data$Gender <- NA
data$Gender[data$Q56 == 1] <- "Male"
data$Gender[data$Q56 == 2] <- "Female"
data$Gender <- as.factor(data$Gender)


# Age
# Q57: What is your year of birth?		
# Write-in response [number]
data$Age <- 2019 - data$Q57
summary(data$Age)


# Education
# (used as numerical variable due to large number of categories)
# Q69: What is your highest level of education or degree?	
# 1: Still at school (comprehensive school, high school, vocational school, etc.)
# 2: Elementary school (folke schoole, kansakoulu)
# 3: Comprehensive school
# 4: Vocational school
# 5: Gymnasium or abitur
# 6: Polytechnic school
# 7: University
# 8: Licentiate or doctoral degree
data$Education <- data$Q69




# Social Class (compared to others)
# Note: Used only for a response to the reviewer
data$SocialClassNum <- data$Q71





# Political.Interest
# Q2_1: How interested would you say you personally are in politics? 
#       Politics in Finland
# 1: Very interested
# 2: Fairly interested
# 3: Not very interested
# 4: Not at all interested
# 5: Can't choose
data$Political.Interest <- NA
data$Political.Interest[data$Q2_1 == 1] <- "Very interested"
data$Political.Interest[data$Q2_1 == 2] <- "Fairly interested"
data$Political.Interest[data$Q2_1 == 3] <- "Not very interested"
data$Political.Interest[data$Q2_1 == 4] <- "Not at all interested"
data$Political.Interest <- factor(data$Political.Interest, levels = c("Very interested", "Fairly interested", "Not very interested", "Not at all interested"))


# Civic.Duty
# Q14_1: How much do you agree or disagree with the following statements?	
#        Finnish citizens residing abroad have a duty to vote in Finland's elections
# 1: Agree strongly
# 2: Somewhat agree
# 3: Neither agree nor disagree
# 4: Somewhat disagree
# 5: Disagree strongly
data$Civic.Duty <- NA
data$Civic.Duty[data$Q14_1 == 1] <- "Agree strongly"
data$Civic.Duty[data$Q14_1 == 2] <- "Somewhat agree"
data$Civic.Duty[data$Q14_1 == 3] <- "Neither agree nor disagree"
data$Civic.Duty[data$Q14_1 == 4] <- "Somewhat disagree"
data$Civic.Duty[data$Q14_1 == 5] <- "Disagree strongly"
data$Civic.Duty <- factor(data$Civic.Duty, levels = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"))




# DATA: Trust in Postal Voting --------------------------

# Trust.Secrecy
# Q13_11: Do you agree or disagree with the following statements regarding postal voting in Finnish parliamentary elections?
#         Postal voting jeopardizes the secrecy of the ballot
# 1: Agree strongly
# 2: Somewhat agree
# 3: Neither agree nor disagree
# 4: Somewhat disagree
# 5: Disagree strongly

data$Trust.Secrecy <- NA
data$Trust.Secrecy[data$Q13_11 == 1] <- "Agree strongly"
data$Trust.Secrecy[data$Q13_11 == 2] <- "Somewhat agree"
data$Trust.Secrecy[data$Q13_11 == 3] <- "Neither agree nor disagree"
data$Trust.Secrecy[data$Q13_11 == 4] <- "Somewhat disagree"
data$Trust.Secrecy[data$Q13_11 == 5] <- "Disagree strongly"
data$Trust.Secrecy <- factor(data$Trust.Secrecy, levels = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"))


# Trust.Fraud
# Q13_12: Do you agree or disagree with the following statements regarding postal voting in Finnish parliamentary elections?
#         Postal voting enables electoral fraud

data$Trust.Fraud <- NA
data$Trust.Fraud[data$Q13_12 == 1] <- "Agree strongly"
data$Trust.Fraud[data$Q13_12 == 2] <- "Somewhat agree"
data$Trust.Fraud[data$Q13_12 == 3] <- "Neither agree nor disagree"
data$Trust.Fraud[data$Q13_12 == 4] <- "Somewhat disagree"
data$Trust.Fraud[data$Q13_12 == 5] <- "Disagree strongly"
data$Trust.Fraud <- factor(data$Trust.Fraud, levels = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"))


# Trust.Combined
# Combination of the two trust measures:
# 1: Q13_11 Postal voting jeopardizes the secrecy of the ballot
# 2: Q13_12 Postal voting enables electoral fraud

# Testing internal consistency
library(psych)
psych::alpha(data.frame(data$Q13_11, data$Q13_12), na.rm = TRUE)
# Cronbach's alpha = 0.85

data$Trust.Combined <- (((data$Q13_11 - 1)/4) + ((data$Q13_12 - 1)/4))/2
summary(data$Trust.Combined)





# ANALYSIS ----------------------------------------------------------------

# FIGURE 1: Voting methods used by respondents ----------------------------

# Creating dataset for Figure 1
a <- data.frame(c("Postal voting", "Advance voting abroad", "Advance voting in Finland", "Election day voting in Finland", "Did not vote"),
                c(sum(data$Vote2019How[!is.na(data$Vote2019How) ] == "Postal voting"), 
                  sum(data$Vote2019How[!is.na(data$Vote2019How) ] == "Advance voting abroad"), 
                  sum(data$Vote2019How[!is.na(data$Vote2019How) ] == "Advance voting in Finland"), 
                  sum(data$Vote2019How[!is.na(data$Vote2019How) ] == "Election day voting in Finland"),
                  sum(data$Vote2019[!is.na(data$Vote2019) ] == "No")
                  ),
                c(1, 0, 0, 0, 0))
colnames(a) <- c("Type", "N", "PostalVote")
a$total <- sum(a$N)
a$total_label <- paste("(N = ", a$N, ")", sep="")
a$share <- (a$N/a$total)*100
a$share_label <- paste(round(a$share, digits = 1), "%", sep="")



# Figure 1: Number of respondents utilizing various voting methods
library(ggplot2)
ggplot(a, aes(x = Type, y = share, fill = PostalVote)) +
  #geom_bar(stat = "identity", width = 0.75, alpha = 0.75, colour = "black", size = 0.5) +
  geom_bar(stat="identity", alpha = 0.75, colour = "black") +
  geom_text(aes(label = share_label), vjust = -2, size = 3) +
  geom_text(aes(label = total_label), vjust = -0.5, size = 3) +
  scale_x_discrete(limits = c("Postal voting", "Advance voting abroad", "Advance voting in Finland", "Election day voting in Finland", "Did not vote"),
                   breaks = c("Postal voting", "Advance voting abroad", "Advance voting in Finland", "Election day voting in Finland", "Did not vote"),
                   labels = c("Postal\nvoting", "Advance voting\nabroad", "Advance voting\nin Finland", "Election day voting\nin Finland", "Did not\nvote")) +
  scale_y_continuous(breaks = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
                     labels = c("0%", "", "20%", "", "40%", "", "60%", "", "80%", "", "100%")) +
  coord_cartesian(xlim = c(0.45, 5.55), ylim = c(0, 100), expand = FALSE) +
  labs(x = NULL, y = NULL) +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black"),
        axis.ticks = element_line(colour = "black"),
        panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(colour = "gray90"),
        panel.grid.minor.y = element_line(colour = "gray90"),
        panel.background = element_blank())

ggsave(filename = "04-figures and models/Fig1 - utilized voting methods.png", width = 15, height = 7.5, units = "cm", dpi = 600)

rm(a)





# ANALYSIS: Data standardization before modeling ----------------------------

#Creating dataset without NAs (to standardize the number of observations)
m.data <- data.frame(PostalVote           = data$PostalVote, 
                     Vote2019How          = data$Vote2019How, 
                     Trust.Secrecy        = data$Trust.Secrecy,
                     Trust.Fraud          = data$Trust.Fraud,
                     Trust.Combined       = data$Trust.Combined,
                     Distance.Objective   = data$Distance.Objective,
                     Distance.Subjective  = data$Distance.Subjective,
                     Distance             = data$Distance, 
                     Gender               = data$Gender, 
                     Age                  = data$Age, 
                     Education            = data$Education, 
                     Political.Interest   = data$Political.Interest, 
                     Civic.Duty           = data$Civic.Duty)
m.data <- na.omit(m.data)




# ANALYSIS --------------------------------------------------------


# ANALYSIS: Models (into the paper) ------------------
m.1 <- glm(PostalVote ~ Distance.Objective   + Trust.Combined  , data = m.data, family = binomial(link = "logit"))
m.2 <- glm(PostalVote ~ Distance.Subjective  + Trust.Combined  , data = m.data, family = binomial(link = "logit"))
m.3 <- glm(PostalVote ~ Distance.Objective   * Trust.Combined  , data = m.data, family = binomial(link = "logit"))
m.4 <- glm(PostalVote ~ Distance.Subjective  * Trust.Combined  , data = m.data, family = binomial(link = "logit"))


# Models with controls
m.5 <- glm(PostalVote ~ Distance.Objective   + Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.6 <- glm(PostalVote ~ Distance.Subjective  + Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.7 <- glm(PostalVote ~ Distance.Objective   * Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.8 <- glm(PostalVote ~ Distance.Subjective  * Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))


library(stargazer)
stargazer(m.1, m.2, m.3, m.4, m.5, m.6, m.7, m.8,
          type = "html", out = "04-figures and models/models_1_to_8.html",
          intercept.bottom = FALSE, star.cutoffs = c(0.05, 0.01, 0.001))





# FIGURE 3: Distance ------------------------------------------------------

library(ggplot2)
library(sjPlot)
library(ggpubr)

ggarrange(
plot_model(m.5,
           type = "pred",
           terms = c("Distance.Objective [all]"))  +
  coord_cartesian(xlim = c(1, 1000), ylim = c(0, 1), expand = FALSE) +
  scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
  scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                           10,   20,   30,   40,   50,   60,   70,   80,   90, 
                           100,  200,  300,  400,  500,  600,  700,  800,  900, 
                           1000), 
                labels = c("1 km",     "", "", "", "", "", "", "", "", 
                           "10 km",    "", "", "", "", "", "", "", "", 
                           "100 km",   "", "", "", "", "", "", "", "", 
                           "1 000 km\n")) +
  labs(title = NULL, 
       x = "Objective distance: Route to the nearest polling station\n(logged scale)", 
       y = "Probability to cast a ballot via post") +
  theme(panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid.major.x = element_line(colour = "gray95"),
        panel.grid.minor.x = element_line(colour = "gray95"),
        panel.grid.major.y = element_line(colour = "gray95"),
        panel.grid.minor.y = element_line(colour = "gray95"),
        panel.background = element_blank(),
        plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),

plot_model(m.6,
           type = "pred",
           terms = c("Distance.Subjective [all]"))  +
  coord_cartesian(xlim = c(1, 1000), ylim = c(0, 1), expand = FALSE) +
  scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
  scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                           10,   20,   30,   40,   50,   60,   70,   80,   90, 
                           100,  200,  300,  400,  500,  600,  700,  800,  900, 
                           1000), 
                labels = c("1 km",     "", "", "", "", "", "", "", "", 
                           "10 km",    "", "", "", "", "", "", "", "", 
                           "100 km",   "", "", "", "", "", "", "", "", 
                           "1 000 km\n")) +
  labs(title = NULL, 
       x = "Subjective distance: Survey response\n(logged scale)", 
       y = "") +
  theme(panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid.major.x = element_line(colour = "gray95"),
        panel.grid.minor.x = element_line(colour = "gray95"),
        panel.grid.major.y = element_line(colour = "gray95"),
        panel.grid.minor.y = element_line(colour = "gray95"),
        panel.background = element_blank(),
        plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),

align = "hv",
nrow = 1)


ggsave(filename = "04-figures and models/Fig3 - distance.png", width = 25, height = 12.5, units = "cm", dpi = 600)





# FIGURE 4: Trust in postal voting ----------------------------------------

library(ggplot2)
library(sjPlot)
library(ggpubr)

ggarrange(
  plot_model(m.5,
             type = "pred",
             terms = c("Trust.Combined"))  +
    coord_cartesian(xlim = c(0, 1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0", "\nDistrust", "0.2", "", "0.4", "", "0.6", "", "0.8", "\nTrust", "1")) +
    labs(title = "Note: Objective distance held constant", 
         x = "Trust in postal voting", 
         y = "Probability to cast a ballot via post") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  plot_model(m.6,
             type = "pred",
             terms = c("Trust.Combined"))  +
    coord_cartesian(xlim = c(0, 1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0", "\nDistrust", "0.2", "", "0.4", "", "0.6", "", "0.8", "\nTrust", "1")) +
    labs(title = "Note: Subjective distance held constant", 
         x = "Trust in postal voting", 
         y = "") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  align = "hv",
  nrow = 1)


ggsave(filename = "04-figures and models/Fig4 - trust.png", width = 25, height = 12.5, units = "cm", dpi = 600)





# FUNCTION: align.legend() to center the legend elements ------------------

align_legend <- function(p, hjust = 0.5)
{
  # extract legend
  g <- cowplot::plot_to_gtable(p)
  grobs <- g$grobs
  legend_index <- which(sapply(grobs, function(x) x$name) == "guide-box")
  legend <- grobs[[legend_index]]
  
  # extract guides table
  guides_index <- which(sapply(legend$grobs, function(x) x$name) == "layout")
  
  # there can be multiple guides within one legend box  
  for (gi in guides_index) {
    guides <- legend$grobs[[gi]]
    
    # add extra column for spacing
    # guides$width[5] is the extra spacing from the end of the legend text
    # to the end of the legend title. If we instead distribute it by `hjust:(1-hjust)` on
    # both sides, we get an aligned legend
    spacing <- guides$width[5]
    guides <- gtable::gtable_add_cols(guides, hjust*spacing, 1)
    guides$widths[6] <- (1-hjust)*spacing
    title_index <- guides$layout$name == "title"
    guides$layout$l[title_index] <- 2
    
    # reconstruct guides and write back
    legend$grobs[[gi]] <- guides
  }
  
  # reconstruct legend and write back
  g$grobs[[legend_index]] <- legend
  g
}



# FIGURE 5: Interaction between trust and distance ------------------------

library(ggplot2)
library(sjPlot)
library(ggpubr)
library(cowplot)


# Generating to separate panels
# (It is needed in order to center the legend labels)

left.panel <-
  plot_model(m.7,
             type = "pred",
             terms = c("Distance.Objective [all]", "Trust.Combined [0.1, 0.5, 0.9]"),
             legend.title = expression(atop("Trust in postal voting",atop("(1=Trust ... 0=Distrust)"))),
             colors = c("#CC6677", "#88CCEE", "#117733")) +
    coord_cartesian(xlim = c(1, 1000), ylim = c(0, 1), expand = FALSE) +
    scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                             10,   20,   30,   40,   50,   60,   70,   80,   90, 
                             100,  200,  300,  400,  500,  600,  700,  800,  900, 
                             1000), 
                  labels = c("1 km",     "", "", "", "", "", "", "", "", 
                             "10 km",    "", "", "", "", "", "", "", "", 
                             "100 km",   "", "", "", "", "", "", "", "", 
                             "1 000 km\n")) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "40%", "", "60%", "", "80%", "", "100%")) +
    labs(title = NULL, 
         x = "Objective distance: Route to the nearest polling station\n(logged scale)", 
         y = "Probability to cast a ballot via post") +
    guides(color = guide_legend(override.aes = list(fill = c("#117733", "#88CCEE", "#CC6677"), color = c("#117733", "#88CCEE", "#CC6677")), reverse = TRUE)) +
    theme(legend.position = "none",
          legend.background = element_rect(),
          legend.key.width = unit(1, "cm"),
          legend.spacing.x = unit(0.3, "cm"),
          legend.text.align = 0,
          legend.title.align = 0,
          legend.box.just = "center",
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_blank(),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin = unit(c(0.5, 0.75, 0.5, 0.5),"cm"))

right.panel <-
  plot_model(m.8,
             type = "pred",
             terms = c("Distance.Subjective [all]", "Trust.Combined [0.1, 0.5, 0.9]"),
             legend.title = expression(atop("Trust in postal voting",atop("(1=Trust ... 0=Distrust)"))),
             colors = c("#CC6677", "#88CCEE", "#117733")) +
    coord_cartesian(xlim = c(1, 1000), ylim = c(0, 1), expand = FALSE) +
    scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                             10,   20,   30,   40,   50,   60,   70,   80,   90, 
                             100,  200,  300,  400,  500,  600,  700,  800,  900, 
                             1000), 
                  labels = c("1 km",     "", "", "", "", "", "", "", "", 
                             "10 km",    "", "", "", "", "", "", "", "", 
                             "100 km",   "", "", "", "", "", "", "", "", 
                             "1 000 km\n")) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "40%", "", "60%", "", "80%", "", "100%")) +
    labs(title = NULL, 
         x = "Subjective distance: Survey response\n(logged scale)", 
         y = "") +
    guides(color = guide_legend(override.aes = list(fill = c("#117733", "#88CCEE", "#CC6677"), color = c("#117733", "#88CCEE", "#CC6677")), reverse = TRUE)) +
    theme(legend.position = "right",
          legend.background = element_rect(),
          legend.key.width = unit(1, "cm"),
          legend.spacing.x = unit(0.3, "cm"),
          legend.text.align = 0,
          legend.title.align = 0,
          legend.box.just = "center",
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_blank(),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin = unit(c(0.5, 0.75, 0.5, 0.5),"cm"))


# Centering the legend labels
right.panel <- ggdraw(align_legend(right.panel))

# Putting it together
ggarrange(left.panel, right.panel, nrow = 1, widths = c(10, 13.35))  
  

ggsave(filename = "04-figures and models/Fig5 - distance vs. trust.png", width = 30, height = 12.5, units = "cm", dpi = 600)

rm(left.panel, right.panel)
rm(m.1, m.2, m.3, m.4, m.5, m.6, m.7, m.8)





# APPENDIX B - Figure B.1: Distribution of respondents from countries ---------------

# MINOR DATA PREPARATIONS:
# To claculate number of FACE survey participants per country, we use two resources: First, we rely on the country in the database of Statistics Finland,
# to where we shipped paper invitation. However, some participants returned in their questionnaires by mail and we included them with a new ID number. 
# For these individuals (n=44), we use information from Q40 in which they were to state their current country of residency.


# Importing FACE survey data
FACE <- read_sav("03-data/FACE data FINAL_subset.sav")

# Selecting only participants' IDs and stated Country (i.e., Q40)
FACE <- FACE[c(5, 13)]

# Importing database of individual IDs and countries where FACE shipped them the paper invitation to survey
library(readxl)
FACE.IDs.cntries <- read_excel("03-data/FACE_IDs_and_countries.xlsx")

# Adding country from the address to survey IDs
FACE <- merge(FACE, FACE.IDs.cntries, by.x = "Q1", by.y = "id", all.x = TRUE)
rm(FACE.IDs.cntries)



# Preparing dataset with counts for barplot
a <- 
  data.frame(           
    Cntry = c("Australia", "Austria", "Belgium", "Canada", "Denmark", "Estonia", "France", "Germany", "Israel", "Italy", 
              "Netherlands", "Norway", "Spain", "Sweden", "Switzerland", "UK", "USA", "Other"),
    N.adr = c(sum(FACE$Country[!is.na(FACE$Country) ] == "AUSTRALIA"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "AUSTRIA"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "BELGIUM"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "CANADA"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "DENMARK"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "ESTONIA"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "FRANCE"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "GERMANY"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "ISRAEL"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "ITALY"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "NETHERLANDS"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "NORWAY"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "SPAIN"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "SWEDEN"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "SWITZERLAND"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "UNITED KINGDOM"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "USA"),
              sum(FACE$Country[!is.na(FACE$Country) ] == "BARBADOS"        |
                    FACE$Country[!is.na(FACE$Country) ] == "BRAZIL"        |
                    FACE$Country[!is.na(FACE$Country) ] == "CHILE"         |
                    FACE$Country[!is.na(FACE$Country) ] == "CHINA"         |
                    FACE$Country[!is.na(FACE$Country) ] == "COSTA RICA"    |
                    FACE$Country[!is.na(FACE$Country) ] == "CROATIA"       |
                    FACE$Country[!is.na(FACE$Country) ] == "CYPRUS"        |
                    FACE$Country[!is.na(FACE$Country) ] == "CZECH REPUBLIC"|
                    FACE$Country[!is.na(FACE$Country) ] == "ECUADOR"       |
                    FACE$Country[!is.na(FACE$Country) ] == "GREECE"        |
                    FACE$Country[!is.na(FACE$Country) ] == "HONG KONG"     |
                    FACE$Country[!is.na(FACE$Country) ] == "ICELAND"       |
                    FACE$Country[!is.na(FACE$Country) ] == "INDONESIA"     |
                    FACE$Country[!is.na(FACE$Country) ] == "IRELAND"       |
                    FACE$Country[!is.na(FACE$Country) ] == "JAPAN"         |
                    FACE$Country[!is.na(FACE$Country) ] == "LATVIA"        |
                    FACE$Country[!is.na(FACE$Country) ] == "LUXEMBOURG"    |
                    FACE$Country[!is.na(FACE$Country) ] == "MALTA"         |
                    FACE$Country[!is.na(FACE$Country) ] == "MEXICO"        |
                    FACE$Country[!is.na(FACE$Country) ] == "MONACO"        |
                    FACE$Country[!is.na(FACE$Country) ] == "NEW ZEALAND"   |
                    FACE$Country[!is.na(FACE$Country) ] == "PARAGUAY"      |
                    FACE$Country[!is.na(FACE$Country) ] == "PHILIPPINES"   |
                    FACE$Country[!is.na(FACE$Country) ] == "POLAND"        |
                    FACE$Country[!is.na(FACE$Country) ] == "PORTUGAL"      |
                    FACE$Country[!is.na(FACE$Country) ] == "RUSSIA"        |
                    FACE$Country[!is.na(FACE$Country) ] == "SINGAPORE"     |
                    FACE$Country[!is.na(FACE$Country) ] == "SLOVENIA"      |
                    FACE$Country[!is.na(FACE$Country) ] == "SOUTH AFRICA"  |
                    FACE$Country[!is.na(FACE$Country) ] == "TAIWAN"        |
                    FACE$Country[!is.na(FACE$Country) ] == "THAILAND"      |
                    FACE$Country[!is.na(FACE$Country) ] == "TURKEY"        |
                    FACE$Country[!is.na(FACE$Country) ] == "UKRAINE"       |
                    FACE$Country[!is.na(FACE$Country) ] == "UNITED ARAB EMIRATES")),
    # adding those respondents who filled in their questionnaires manually (ID (i.e.,Q1) > 300,000 indicates these people
    N.other = c(sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 6),           
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 16),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 15),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 5),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 11),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 14),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 10),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 3),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 17),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 13),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 12),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 8),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 9),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 1),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 7),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 4),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 2),
                sum(FACE$Q40[!is.na(FACE$Q40) & FACE$Q1 > 300000] == 18))
  )

# Summing up numbers of respondents per country
a$N <- a$N.adr + a$N.other

# Partial sums are not needed anymore
a$N.adr <- NULL
a$N.other <- NULL

# Calculating remaining figures (and labels) to be used
a$Total <- sum(a$N)
a$Total.Label <- paste("(N=", a$N, ")", sep="")
a$Share <- (a$N/a$Total)*100
a$Share.Label <- paste(round(a$Share, digits = 1), "%", sep="")
a$Cntry <- factor(a$Cntry, levels = a$Cntry[order(a$Share)])


# Figure 1: Representation of countries in data
library(ggplot2)
ggplot(a, aes(x = Cntry, y = Share)) +
  geom_bar(stat = "identity", width = 0.75, alpha = 0.75, colour = "black", size = 0.5) +
  geom_text(aes(label = Share.Label), vjust = -2, size = 3) +
  geom_text(aes(label = Total.Label), vjust = -0.5, size = 3) +
  scale_x_discrete(limits = rev(levels(a$Cntry))) +
  scale_y_continuous(breaks = c(0:12),
                     labels = c("0%", "", "2%", "", "4%", "", "6%", "", "8%", "", "10%", "", "12%")) +
  coord_cartesian(xlim = c(0.4, 18.6), ylim = c(-0.01, 11), expand = FALSE) +
  labs(x = NULL, y = NULL) +
  theme(strip.background = element_rect(colour = "black"),
        panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(colour = "gray90"), panel.grid.minor.y = element_line(colour = "gray90"),
        panel.background = element_blank(),
        axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),"cm"))

ggsave(filename = "04-figures and models/FigB.1 - Representation of countries.png", width = 25, height = 15, units = "cm", dpi = 600)  
rm(a, FACE)





# ONLINE APPENDIX: Trust measure comparison ------------------

#Creating dataset without NAs (to standardize the number of observations)
m.data <- data.frame(PostalVote           = data$PostalVote, 
                     Vote2019How          = data$Vote2019How, 
                     Trust.Secrecy        = data$Trust.Secrecy,
                     Trust.Fraud          = data$Trust.Fraud,
                     Trust.Combined       = data$Trust.Combined,
                     Distance.Objective   = data$Distance.Objective,
                     Distance.Subjective  = data$Distance.Subjective,
                     Gender               = data$Gender, 
                     Age                  = data$Age, 
                     Education            = data$Education, 
                     Political.Interest   = data$Political.Interest, 
                     Civic.Duty           = data$Civic.Duty)
m.data <- na.omit(m.data)


m.1 <- glm(PostalVote ~ Distance.Objective   + Trust.Secrecy   + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.2 <- glm(PostalVote ~ Distance.Objective   + Trust.Fraud     + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.3 <- glm(PostalVote ~ Distance.Objective   + Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.4 <- glm(PostalVote ~ Distance.Subjective  + Trust.Secrecy   + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.5 <- glm(PostalVote ~ Distance.Subjective  + Trust.Fraud     + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))
m.6 <- glm(PostalVote ~ Distance.Subjective  + Trust.Combined  + Gender + Age + Education + Political.Interest + Civic.Duty, data = m.data, family = binomial(link = "logit"))

library(stargazer)
stargazer(m.1, m.2, m.3, m.4, m.5, m.6, 
          type = "html", out = "04-figures and models/models_trust_measure_comparison.html",
          intercept.bottom = FALSE, star.cutoffs = c(0.05, 0.01, 0.001))


# FIGURE A2: Comparison of the trust measures
library(ggplot2)
library(sjPlot)
library(ggpubr)

ggarrange(
  plot_model(m.1,
             type = "pred",
             terms = c("Trust.Secrecy"))  +
    coord_cartesian(xlim = c(0.9, 5.1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_discrete(limits = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"), 
                     labels = c("Agree\nstrongly", "Somewhat\nagree", "Neither agree\nnor disagree\n", "Somewhat\ndisagree", "Disagree\nstrongly")) +
    labs(title = "Note: Objective distance held constant", 
         x = "Postal voting jeopardizes the secrecy of the ballot", 
         y = "Probability to cast a ballot via post") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          axis.text = element_text(size = 7),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  plot_model(m.4,
             type = "pred",
             terms = c("Trust.Secrecy"))  +
    coord_cartesian(xlim = c(0.9, 5.1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_discrete(limits = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"), 
                     labels = c("Agree\nstrongly", "Somewhat\nagree", "Neither agree\nnor disagree\n", "Somewhat\ndisagree", "Disagree\nstrongly")) +
    labs(title = "Note: Subjective distance held constant", 
         x = "Postal voting jeopardizes the secrecy of the ballot", 
         y = "") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          axis.text = element_text(size = 7),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  plot_model(m.2,
             type = "pred",
             terms = c("Trust.Fraud"))  +
    coord_cartesian(xlim = c(0.9, 5.1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_discrete(limits = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"), 
                     labels = c("Agree\nstrongly", "Somewhat\nagree", "Neither agree\nnor disagree\n", "Somewhat\ndisagree", "Disagree\nstrongly")) +
    labs(title = "Note: Objective distance held constant", 
         x = "Postal voting enables electoral fraud", 
         y = "Probability to cast a ballot via post") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          axis.text = element_text(size = 7),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  plot_model(m.5,
             type = "pred",
             terms = c("Trust.Fraud"))  +
    coord_cartesian(xlim = c(0.9, 5.1), ylim = c(0, 1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1), labels = c("0%", "", "20%", "", "  40%", "", "60%", "", "80%", "", "100%")) +
    scale_x_discrete(limits = c("Agree strongly", "Somewhat agree", "Neither agree nor disagree", "Somewhat disagree", "Disagree strongly"), 
                     labels = c("Agree\nstrongly", "Somewhat\nagree", "Neither agree\nnor disagree\n", "Somewhat\ndisagree", "Disagree\nstrongly")) +
    labs(title = "Note: Subjective distance held constant", 
         x = "Postal voting enables electoral fraud", 
         y = "") +
    theme(plot.title = element_text(size = 8, hjust = 1),
          axis.text = element_text(size = 7),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid.major.x = element_line(colour = "gray95"),
          panel.grid.minor.x = element_line(colour = "gray95"),
          panel.grid.major.y = element_line(colour = "gray95"),
          panel.grid.minor.y = element_line(colour = "gray95"),
          panel.background = element_blank(),
          plot.margin=unit(c(0.75, 0.75, 0.75, 0.75),"cm")),
  
  align = "hv",
  nrow = 2, ncol = 2)


ggsave(filename = "04-figures and models/FigA2 - trust comparison.png", width = 20, height = 20, units = "cm", dpi = 600)




# SUMMARY STATISTICS: Comparison of subsamples ----------------------------

# Full dataset (n=2101) of relevant variables
data.full <- data.frame(PostalVote           = data$PostalVote, 
                        Vote2019How          = data$Vote2019How, 
                        Trust.Secrecy        = data$Trust.Secrecy,
                        Trust.Fraud          = data$Trust.Fraud,
                        Trust.Combined       = data$Trust.Combined,
                        Distance.Objective   = data$Distance.Objective,
                        Distance.Subjective  = data$Distance.Subjective,
                        Gender               = data$Gender, 
                        Age                  = data$Age, 
                        Education            = data$Education, 
                        Political.Interest   = data$Political.Interest, 
                        Civic.Duty           = data$Civic.Duty)


# Dataset of voters (n=983)
data.voters <- data.frame(PostalVote           = data$PostalVote,
                          Vote2019How          = data$Vote2019How, 
                          Trust.Secrecy        = data$Trust.Secrecy,
                          Trust.Fraud          = data$Trust.Fraud,
                          Trust.Combined       = data$Trust.Combined,
                          Distance.Objective   = data$Distance.Objective,
                          Distance.Subjective  = data$Distance.Subjective,
                          Gender               = data$Gender, 
                          Age                  = data$Age, 
                          Education            = data$Education, 
                          Political.Interest   = data$Political.Interest, 
                          Civic.Duty           = data$Civic.Duty)

data.voters <- subset(data.voters, !is.na(Vote2019How))


# Data used for model estimation (n=664)
data.models <- data.frame(PostalVote           = data$PostalVote, 
                          Vote2019How          = data$Vote2019How, 
                          Trust.Secrecy        = data$Trust.Secrecy,
                          Trust.Fraud          = data$Trust.Fraud,
                          Trust.Combined       = data$Trust.Combined,
                          Distance.Objective   = data$Distance.Objective,
                          Distance.Subjective  = data$Distance.Subjective,
                          Gender               = data$Gender, 
                          Age                  = data$Age, 
                          Education            = data$Education, 
                          Political.Interest   = data$Political.Interest, 
                          Civic.Duty           = data$Civic.Duty)

data.models <- na.omit(data.models)


# Generating the summaries for the data frames
library(summarytools)
dfSummary(data.full)
dfSummary(data.voters)
dfSummary(data.models)


# FOLLOWING MATERIALS WERE MADE IN RESPONSE TO THE REVIEWERS' COMMENTS DURING PEER-REVIEW: ---------------------------------------------------
# NOTE: These materials are not included in the paper, but were included in the response to reviewers letters


# FOR THE REVIEWER: Development of trust measures over time ---------------------------------------------------

library(ggpubr)

ggarrange(
  
  ggplot(data, aes(x = StartDate, y = Q13_11)) +
    geom_point() +
    geom_smooth() +
    coord_cartesian(ylim = c(0.9, 5.1), expand = FALSE) +
    scale_y_continuous(breaks = c(1:5), labels = c("1=Agree\nstrongly", "2", "3", "4", "5=Disagree\nstrongly"))+
    labs(x = "", y = "Postal voting jeopardizes\nthe secrecy of the ballot") +
    theme(legend.position = "none",
          axis.text = element_text(colour = "black"),
          axis.ticks = element_line(colour = "black"),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid = element_line(colour = "gray90"),
          panel.background = element_blank()),
  
  ggplot(data, aes(x = StartDate, y = Q13_12)) +
    geom_point() +
    geom_smooth() +
    coord_cartesian(ylim = c(0.9, 5.1), expand = FALSE) +
    scale_y_continuous(breaks = c(1:5), labels = c("1=Agree\nstrongly", "2", "3", "4", "5=Disagree\nstrongly"))+
    labs(x = "", y = "Postal voting enables electoral fraud") +
    theme(legend.position = "none",
          axis.text = element_text(colour = "black"),
          axis.ticks = element_line(colour = "black"),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid = element_line(colour = "gray90"),
          panel.background = element_blank()),
  
  ggplot(data, aes(x = StartDate, y = Trust.Combined)) +
    geom_point() +
    geom_smooth() +
    coord_cartesian(ylim = c(-0.1, 1.1), expand = FALSE) +
    scale_y_continuous(breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1), labels = c("0=Low\ntrust", "0.2", "0.4", "0.6", "0.8", "1=High\ntrust"))+
    labs(x = "", y = "Combined measure of trust\nin postal voting") +
    theme(legend.position = "none",
          axis.text = element_text(colour = "black"),
          axis.ticks = element_line(colour = "black"),
          panel.border = element_rect(fill = "transparent"),
          strip.background = element_rect(colour = "black"),
          panel.grid = element_line(colour = "gray90"),
          panel.background = element_blank()),
  
  align = "hv",
  nrow = 3) +
  theme(plot.margin = unit(c(0.5, 0.5, 0.5, 0.5),"cm"))


ggsave(filename = "04-figures and models/RR - trust over time.png", width = 15, height = 25, units = "cm", dpi = 600)




# FOR THE REVIEWER: Impact of "social class" ----------------------------

# Data standardization before modeling
# Creating dataset without NAs (to standardize the number of observations)
soc.class.data <- data.frame(PostalVote           = data$PostalVote, 
                             Vote2019How          = data$Vote2019How, 
                             Trust.Secrecy        = data$Trust.Secrecy,
                             Trust.Fraud          = data$Trust.Fraud,
                             Trust.Combined       = data$Trust.Combined,
                             Distance.Objective   = data$Distance.Objective,
                             Distance.Subjective  = data$Distance.Subjective,
                             Distance             = data$Distance, 
                             Gender               = data$Gender, 
                             Age                  = data$Age, 
                             Education            = data$Education, 
                             SocialClassNum       = data$SocialClassNum, 
                             Political.Interest   = data$Political.Interest, 
                            Civic.Duty           = data$Civic.Duty)
soc.class.data <- na.omit(soc.class.data)


# SOCIAL CLASS: Models
soc.class.1    <- glm(PostalVote ~ Distance.Objective   + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.1.no <- glm(PostalVote ~ Distance.Objective   + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.2    <- glm(PostalVote ~ Distance.Subjective  + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.2.no <- glm(PostalVote ~ Distance.Subjective  + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.3    <- glm(PostalVote ~ Trust.Secrecy        + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.3.no <- glm(PostalVote ~ Trust.Secrecy        + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.4    <- glm(PostalVote ~ Trust.Fraud          + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.4.no <- glm(PostalVote ~ Trust.Fraud          + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.5    <- glm(PostalVote ~ Trust.Combined       + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.5.no <- glm(PostalVote ~ Trust.Combined       + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))


library(stargazer)
stargazer(soc.class.1, soc.class.1.no, 
          soc.class.2, soc.class.2.no, 
          soc.class.3, soc.class.3.no, 
          soc.class.4, soc.class.4.no, 
          soc.class.5, soc.class.5.no,
          type = "html", out = "04-figures and models/models_RR_social-trust.html",
          intercept.bottom = FALSE, star.cutoffs = c(0.05, 0.01, 0.001))

rm(soc.class.1, soc.class.1.no, 
   soc.class.2, soc.class.2.no, 
   soc.class.3, soc.class.3.no, 
   soc.class.4, soc.class.4.no, 
   soc.class.5, soc.class.5.no)




# SOCIAL CLASS: Interactions
soc.class.3.a    <- glm(PostalVote ~ Trust.Secrecy*Distance.Objective     + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.3.a.no <- glm(PostalVote ~ Trust.Secrecy*Distance.Objective     + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.3.b    <- glm(PostalVote ~ Trust.Secrecy*Distance.Subjective    + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.3.b.no <- glm(PostalVote ~ Trust.Secrecy*Distance.Subjective    + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.4.a    <- glm(PostalVote ~ Trust.Fraud*Distance.Objective       + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.4.a.no <- glm(PostalVote ~ Trust.Fraud*Distance.Objective       + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.4.b    <- glm(PostalVote ~ Trust.Fraud*Distance.Subjective      + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.4.b.no <- glm(PostalVote ~ Trust.Fraud*Distance.Subjective      + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))

soc.class.5.a    <- glm(PostalVote ~ Trust.Combined*Distance.Objective    + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.5.a.no <- glm(PostalVote ~ Trust.Combined*Distance.Objective    + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.5.b    <- glm(PostalVote ~ Trust.Combined*Distance.Subjective   + Gender + Age + Education + SocialClassNum + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))
soc.class.5.b.no <- glm(PostalVote ~ Trust.Combined*Distance.Subjective   + Gender + Age + Education                  + Political.Interest + Civic.Duty, data = soc.class.data, family = binomial(link = "logit"))


library(stargazer)
stargazer(soc.class.3.a, soc.class.3.a.no, soc.class.3.b, soc.class.3.b.no,
          soc.class.4.a, soc.class.4.a.no, soc.class.4.b, soc.class.4.b.no,
          soc.class.5.a, soc.class.5.a.no, soc.class.5.b, soc.class.5.b.no,
          type = "html", out = "04-figures and models/models_RR_social-trust-interactions.html",
          intercept.bottom = FALSE, star.cutoffs = c(0.05, 0.01, 0.001))


rm(soc.class.3.a, soc.class.3.a.no, soc.class.3.b, soc.class.3.b.no,
   soc.class.4.a, soc.class.4.a.no, soc.class.4.b, soc.class.4.b.no,
   soc.class.5.a, soc.class.5.a.no, soc.class.5.b, soc.class.5.b.no)

rm(soc.class.data)






# FOR THE REVIEWER: Connection between distance and trust -----------------

library(ggpubr)

ggarrange(
  
ggplot(data, aes(x = Distance.Subjective, y = Trust.Combined)) +
  geom_point() +
  geom_smooth() +
  coord_cartesian(xlim = c(1, 1000), ylim = c(-0.01, 1.01), expand = FALSE) +
  scale_y_continuous(breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1), labels = c("0=Low\ntrust", "0.2", "0.4", "0.6", "0.8", "1=High\ntrust"))+
  scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                           10,   20,   30,   40,   50,   60,   70,   80,   90, 
                           100,  200,  300,  400,  500,  600,  700,  800,  900, 
                           1000), 
                labels = c("1 km",     "", "", "", "", "", "", "", "", 
                           "10 km",    "", "", "", "", "", "", "", "", 
                           "100 km",   "", "", "", "", "", "", "", "", 
                           "1 000 km\n")) +
  labs(x = "Subjective distance: Survey response\n(logged scale)", 
       y = "Combined measure of trust\nin postal voting") +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black"),
        axis.ticks = element_line(colour = "black"),
        panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid = element_line(colour = "gray90"),
        panel.background = element_blank(),
        plot.margin = unit(c(0.5, 0.75, 0.5, 0.5),"cm")),

ggplot(data, aes(x = Distance.Objective, y = Trust.Combined)) +
  geom_point() +
  geom_smooth() +
  coord_cartesian(xlim = c(1, 1000), ylim = c(-0.01, 1.01), expand = FALSE) +
  scale_y_continuous(breaks = c(0, 0.2, 0.4, 0.6, 0.8, 1), labels = c("0=Low\ntrust", "0.2", "0.4", "0.6", "0.8", "1=High\ntrust"))+
  scale_x_log10(breaks = c(1,    2,    3,    4,    5,    6,    7,    8,    9, 
                           10,   20,   30,   40,   50,   60,   70,   80,   90, 
                           100,  200,  300,  400,  500,  600,  700,  800,  900, 
                           1000), 
                labels = c("1 km",     "", "", "", "", "", "", "", "", 
                           "10 km",    "", "", "", "", "", "", "", "", 
                           "100 km",   "", "", "", "", "", "", "", "", 
                           "1 000 km\n")) +
  labs(x = "Objective distance: Route to the nearest polling station\n(logged scale)", 
       y = "") +
  theme(legend.position = "none",
        axis.text = element_text(colour = "black"),
        axis.ticks = element_line(colour = "black"),
        panel.border = element_rect(fill = "transparent"),
        strip.background = element_rect(colour = "black"),
        panel.grid = element_line(colour = "gray90"),
        panel.background = element_blank(),
        plot.margin = unit(c(0.5, 0.75, 0.5, 0.5),"cm")),

align = "hv",
nrow = 1)


ggsave(filename = "04-figures and models/RR - distance vs trust.png", width = 28, height = 14, units = "cm", dpi = 600)
